﻿#pragma once
#include "Types.h"

namespace mdb
{
	class Tick
	{
	public:
		static constexpr unsigned int TableID = 0x0001;
		//交易日
		Int64Type TradingDay;
		//交易所代码
		ExchangeIDType ExchangeID;
		//合约代码
		InstrumentIDType InstrumentID;
		//Tick时间戳
		Int64Type UpdateTs;
		//最新价
		DecimalType LastPrice;
		//最新成交量
		DoubleType LastTraded;
		//总成交量
		DoubleType Volume;
		//持仓量
		DoubleType OpenInterest;
		//成交额
		DecimalType Turnover;
		//买一价
		DecimalType BidPrice1;
		//买一量
		DoubleType BidVolume1;
		//卖一价
		DecimalType AskPrice1;
		//卖一量
		DoubleType AskVolume1;
		//昨结算价
		DecimalType PreSettlementPrice;
		//昨收盘价
		DecimalType PreClosePrice;
		//左持仓量
		DoubleType PreOpenInterest;
		//最高成交价
		DecimalType HighestPrice;
		//最低成交价
		DecimalType LowestPrice;
		
		static Tick* Allocate();
		void Free();
		const char* GetString() const;
		int GetSqlString(char* buff) const;
		const char* GetDebugString() const;
	};
	class Bar
	{
	public:
		static constexpr unsigned int TableID = 0x0002;
		//交易日
		Int64Type TradingDay;
		//交易所代码
		ExchangeIDType ExchangeID;
		//合约代码
		InstrumentIDType InstrumentID;
		//Tick时间戳
		Int64Type UpdateTs;
		//Bar精度
		PreceType Prece;
		//最新成交量
		DoubleType LastTraded;
		//总成交量
		DoubleType Volume;
		//成交额
		DoubleType Turnover;
		//持仓量
		DoubleType OpenInterest;
		//Bar开盘价
		DecimalType Open;
		//Bar最高价
		DecimalType High;
		//Bar最低价
		DecimalType Low;
		//Bar收盘价
		DecimalType Close;
		//日内最高成交价
		DecimalType HighestPrice;
		//日内最低成交价
		DecimalType LowestPrice;
		//品种类型
		ProductClassType ProductClass;
		//标的合约
		InstrumentIDType UnderlyingID;
		
		static Bar* Allocate();
		void Free();
		const char* GetString() const;
		int GetSqlString(char* buff) const;
		const char* GetDebugString() const;
	};

	extern thread_local Tick t_CompareTick;
	extern thread_local Bar t_CompareBar;

}

